﻿using Model.Admin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace DAL
{
    public class AdminDal
    {
        public AdminDal(MyContext context)
        {
            Context = context;
        }

        public MyContext Context { get; }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="name">用户名</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public dynamic Login(string name, string pwd)
        {
            try
            {
                var res = Context.Admin.Where(x => x.Name == name).Count();
                if (res == 0)
                {
                    return -1;
                }
                else
                {
                    var c = Context.Admin.Where(x => x.Name == name && x.Pwd == pwd).Count();
                    if (c == 0)
                    {
                        return -2;
                    }
                    else
                    {
                        var info = Context.Admin.Where(x => x.Name == name && x.Pwd == pwd).FirstOrDefault();
                        return info;
                    }


                }
              
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
